#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2018/1/16 0016 20:22
# @Author  : Arliki
# @File    : ip_check.py
import telnetlib
import pandas as pd
import requests

def run():
    ip_all = pd.read_csv('../../../common_lib/ip_pool.csv', header=None, index_col=None, encoding='utf-8')
    for i in range(len(ip_all)):
        # ip_host="http://"+ip_all.loc[i,][0]+":"+str(ip_all.loc[i,][1])
        # ip_host={"http":ip_host}
        ip_host = str(ip_all.loc[i,][0])
        ip_port = str(ip_all.loc[i,][1])
        tp = [(str(ip_host), str(ip_port))]
        try:
            telnetlib.Telnet(ip_host, port=ip_port, timeout=3)
            upd = pd.DataFrame(tp)
            upd.to_csv('ip_ok.csv', header=False, index=False, encoding='utf-8', mode='a+')
            print("ip", ip_host, 'is ok')
        except:
            print("ip", ip_host, 'is not ok')


if __name__ == '__main__':
    run()
